package com.theten52.demo.io;

import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * Block IO 客户端
 *
 * @author wangjin
 * @date 2021/3/11
 */
public class BlockIOEchoClient {
    public static void main(String[] args) throws Exception {
        Socket client = new Socket(HostInfo.HOST_NAME, HostInfo.PORT);
        Scanner scan = new Scanner(client.getInputStream());
        scan.useDelimiter(System.lineSeparator());
        PrintStream out = new PrintStream(client.getOutputStream());
        boolean flag = true;
        while (flag) {
            String inputData = InputUtil.getString("请输入要发送的内容：").trim();
            out.println(inputData);
            if (scan.hasNextLine()) {
                String str = scan.nextLine();
                System.out.println(str);
            }
            if ("bye bye".equalsIgnoreCase(inputData)) {
                flag = false;
            }
        }
        client.close();
    }
}